package com.example.administrator.foodrowfresh.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.foodrowfresh.R;
import com.example.administrator.foodrowfresh.models.TimeLimit;
import com.example.administrator.foodrowfresh.views.FlashSale;

import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/5/4.
 */
public class TimeLimitRecyclerAdapter extends RecyclerView.Adapter<TimeLimitRecyclerAdapter.MyViewHolder> {

    private List<TimeLimit.DataBean.FlashSaleBean> flashSaleBeans;
    private Context mContext;

    public TimeLimitRecyclerAdapter(List<TimeLimit.DataBean.FlashSaleBean> flashSaleBeans,Context mContext) {
        super();
        this.flashSaleBeans = flashSaleBeans;
        this.mContext=mContext;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_timelimit_item,parent,false);
        MyViewHolder holder=new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (holder!=null)
        {
            holder.textViewname.setText(flashSaleBeans.get(position).getProductName());
            Log.d("qq",flashSaleBeans.get(position).getProductName());
            holder.textViewprice.setText("￥"+flashSaleBeans.get(position).getPeriodMoney());
            holder.textViewweight.setText(" /"+flashSaleBeans.get(position).getWeight());
            x.image().bind(holder.imageView,flashSaleBeans.get(position).getImage());
        }
    }

    @Override
    public int getItemCount() {
        return flashSaleBeans==null?0:flashSaleBeans.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public ImageView imageView;
        public TextView textViewname;
        public TextView textViewprice;
        public TextView textViewweight;
        public MyViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.image_timelimit);
            textViewname= (TextView) itemView.findViewById(R.id.tv_timelimit_name);
            textViewprice= (TextView) itemView.findViewById(R.id.tv_timelimit_price);
            textViewweight= (TextView) itemView.findViewById(R.id.tv_timelimit_weight);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, FlashSale.class);
                    mContext.startActivity(intent);
                }
            });
        }
    }
}
